package ar.edu.itba.bundundu.domain;

import java.util.ArrayList;

public class CalendarSharing {

  private ArrayList<CalendarItem> calendars;

  public CalendarSharing() {
    this.calendars = new ArrayList<CalendarItem>();
  }

  public void add(String name, String url) {
    CalendarItem item = new CalendarItem(name, url);
    calendars.add(item);
  }

  public void addFeed(String calendar, String email, String level)
      throws Exception {
    CalendarItem item = this.getCalendarIndex(calendar);
    if (item == null) {
      throw new Exception("the calendar " + calendar + "does not exist.");
    }
    item.addFeed(email, level);

  }

  public int getSize() {
    return this.calendars.size();
  }
  
  public CalendarItem get(int i){
    return this.calendars.get(i);
  }

  public void addItem(CalendarItem item){
    this.calendars.add(item);
  }
  
  private CalendarItem getCalendarIndex(String name) {
    for (int i = 0; i < calendars.size(); i++) {
      CalendarItem cal = calendars.get(i);
      if (cal.name == name) {
        return cal;
      }
    }
    return null;

  }

}
